package com.homepage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;

/**
 * A Company.
 */
@Entity
@Table(name = "company")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Getter
@Setter
@ToString
public class Company implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotNull
    @Size(max = 30)
    @Id
    @Column(name = "id", length = 30, nullable = false)
    private String id;

    @NotNull
    @Size(max = 150)
    @Column(name = "street_address", length = 150, nullable = false)
    private String streetAddress;

    @Size(max = 10)
    @Column(name = "postal_code", length = 10)
    private String postalCode;

    @NotNull
    @Size(max = 16)
    @Column(name = "city", length = 16, nullable = false)
    private String city;

    @NotNull
    @Size(max = 16)
    @Column(name = "state_province", length = 16, nullable = false)
    private String stateProvince;

    @NotNull
    @Column(name = "expiry_date", nullable = false)
    private ZonedDateTime expiryDate;

    @OneToMany(mappedBy = "company")
//    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "employeePortrait", "company" }, allowSetters = true)
    private Set<Employee> employees = new HashSet<>();

    @OneToMany(mappedBy = "company")
//    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "featuretteImage", "company" }, allowSetters = true)
    private Set<Featurette> featurettes = new HashSet<>();

    @OneToMany(mappedBy = "company")
//    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "headlineImage", "company" }, allowSetters = true)
    private Set<Headline> headlines = new HashSet<>();

    @OneToMany(mappedBy = "company")
//    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "partnerLogo", "company" }, allowSetters = true)
    private Set<Partner> partners = new HashSet<>();

    public String getId() {
        return this.id;
    }

    public Company id(String id) {
        this.setId(id);
        return this;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getStreetAddress() {
        return this.streetAddress;
    }

    public Company streetAddress(String streetAddress) {
        this.setStreetAddress(streetAddress);
        return this;
    }

    public void setStreetAddress(String streetAddress) {
        this.streetAddress = streetAddress;
    }

    public String getPostalCode() {
        return this.postalCode;
    }

    public Company postalCode(String postalCode) {
        this.setPostalCode(postalCode);
        return this;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getCity() {
        return this.city;
    }

    public Company city(String city) {
        this.setCity(city);
        return this;
    }

    public void setCity(String city) {
        this.city = city;
    }
    public Company expiryDate(ZonedDateTime expiryDate) {
        this.setExpiryDate(expiryDate);
        return this;
    }
    public String getStateProvince() {
        return this.stateProvince;
    }

    public Company stateProvince(String stateProvince) {
        this.setStateProvince(stateProvince);
        return this;
    }


//    public Company headlines(Set<Headline> headlines) {
//        this.setHeadlines(headlines);
//        return this;
//    }
//
//    public Company partners(Set<Partner> partners) {
//        this.setPartners(partners);
//        return this;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Company)) {
            return false;
        }
        return id != null && id.equals(((Company) o).id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }

}
